﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;

using System.Xml;

using System.Xml.Serialization;

using System.IO;


namespace HaGisPack
{
   public  class FFileHelper
    {

        public static bool SaveToBinary(string fname, object obj)
        {


            BinaryFormatter bf = new BinaryFormatter();

            Stream stream = new FileStream(fname, FileMode.Create, FileAccess.Write);


            try
            {

                bf.Serialize(stream, obj);

                stream.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("错误：" + ex.Message);
                return false;

            }


            return true;

        }



        public static object OpenFromBinary(string fname, ref  bool b)
        {


            BinaryFormatter bf = new BinaryFormatter();

            //将文件属性设为普通，哈哈

            Stream stream = new FileStream(fname, FileMode.Open, FileAccess.Read, FileShare.None);

            object obj;

            try
            {

                obj = bf.Deserialize(stream);


                stream.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show("错误：" + ex.Message);
                return null;
               

            }

            b = true;
            return obj;


        }


        public static bool SaveToXml(string fanme, object obj)
        {


            

            return true;
 
        }
    }
}
